$(function(){
	showCondition(true, 1, 0, 1, [1, 1, 0, 0, 0,0]);//加载查询条件
	scrollTo(0,0);
	tabId=$("#tabContent > .tab-pane.active").attr("id");
	ajaxCntDrgFeeStage = {"single":0,"multiple":0};
	totalQuota = [
	                  {name:"产能指标", 
	                   data:[
	                         {"quotaCode":"TotalCaseCnt", "quotaName":"患者数"}, 
	                         {"quotaCode":"TotalFee", "quotaName":"总费用(万元)"},
	                         {"quotaCode":"AvgFee", "quotaName":"次均费用(元)"},
	                         {"quotaCode":"DrugFee", "quotaName":"药品费用(万元)"}, 
	                         {"quotaCode":"DrugRatio", "quotaName":"药占比(%)"},
	                         {"quotaCode":"MaterialFee", "quotaName":"耗材费(万元)"}, 
	                         {"quotaCode":"MaterialRatio", "quotaName":"耗占比(%)"},
	                         {"quotaCode":"OrderQuantity", "quotaName":"医嘱项数"}
	                         ]
	                  }
	                  ];
	
	
	$(document).ajaxStop(function(){
		reloadNav();
	});
	orderSpecialDep='';
	$.post(contextPath+'/feeStage/getOrderSpecialDep.dhc',function(result){
		if(result.data.length>0){
			for(var o in result.data){
				orderSpecialDep+="'"+result.data[o].DEPDESC+"',";
			}
		}
		paramTabPage[tabId]['orderSpecialDep'] = orderSpecialDep==''?'':orderSpecialDep.substring(0,orderSpecialDep.length-1);
	});
	var verCode = '';
	$.ajax({
		url: contextPath+'/DRGVersion/getDrgVerCode.dhc',
		type: 'POST',
		dataType:"json",
		success:function(data){
			verCode = data.data;
			loadDrgFeeStageData();
		}
	});
	
	function loadDrgFeeStageData(){
		//MDC列表
//		$.getJSON(contextPath+'/MDCGroup/findAllMDCGroup.dhc',{
//			'dateFrom':paramTabPage[tabId].dateFrom,
//			'dateTo':paramTabPage[tabId].dateTo
//			},function(dep){
//			$.each(dep.data,function(i,n){
//				$('#'+tabId+' #mdcList').append('<li><a class="depGroup" title="'+n[1]+'" id="'+n[0]
//						+'">'+n[0]+'</a></li>');				
//			});
		$.getJSON(contextPath+'/MDCGroup/findAllMDC.dhc',{"verCode":sysConfig.GROUP_VER},function(dep){
			$.each(dep.data,function(i,n){
				$('#'+tabId+' #mdcList').append('<li><a class="depGroup" title="'+n.MDC_DESC+'" id="'+n.MDC_CODE
						+'">'+n.MDC_CODE+'</a></li>');				
			});	
			
			if(paramTabPage[tabId].parmdcCode == '' || paramTabPage[tabId].parmdcCode == undefined){
				$('#'+tabId+' #mdcList').children().first().find('a').click();
			} else {
				$('#'+tabId+' #mdcList #'+paramTabPage[tabId].parmdcCode).addClass('depActive');
				
				//drgs列表
				var param = drgUI.setAjaxData(tabId);
				$.post(contextPath+'/DRGs/getDrgsByParam.dhc',param,
					function(dep){
						$('#'+tabId+' #drgList').html('');
						$('#'+tabId+' #drgList').append('<option value="">全部DRG</option>');
						$.each(dep.data,function(i,n){
							$('#'+tabId+' #drgList').append('<li><a class="dep" title="'+n.DRGDESC+'" id="'+n.DRGCODE+'">'+n.DRGCODE+'</a></li>');
						});
						
						if(paramTabPage[tabId].pardrgCode != '' && paramTabPage[tabId].pardrgCode != undefined){
							$('#'+tabId+' #drgList #'+paramTabPage[tabId].pardrgCode).click();
						}
				});
				loadQuotaData('drgs',paramTabPage[tabId].parmdcDesc);
			}
		});
		
		//全院点击事件
		$('#'+tabId).off('click','.hosp');
		$('#'+tabId).on('click','.hosp',function(){
			$('#'+tabId+' .dep').removeClass('depActive');
			$('#'+tabId+' .depGroup').removeClass('depActive');
			$(this).addClass('depActive');
			paramTabPage[tabId]['pardepgroupCode'] = '';
			paramTabPage[tabId]['pardepCode'] = '';
			paramTabPage[tabId]['parmdcCode'] = '';
			paramTabPage[tabId]['pardrgCode'] = '';
			$('#'+tabId+' .currDepOrDepgroup').html('<i class="fa fa-hospital-o"></i>全院');
			
			//DRG列表
			var param = drgUI.setAjaxData(tabId);
			param.parmdcCode = "";
			$.post(contextPath+'/DRGs/getDrgsByParam.dhc',param).done(
				function(dep){
					$('#'+tabId+' #drgList').html('');
					$('#'+tabId+' #drgList').append('<option value="">全部DRG</option>');
					$.each(dep.data,function(i,n){
						$('#'+tabId+' #drgList').append('<option value="'+n.DRGCODE+'">'+n.DRGCODE+'-'+n.DRGDESC+'</option>');
					});
				});
			//加载表格
			$('#'+tabId+' #singleDrgs').hide();
			$('#'+tabId+' #multilDrgs').show();
			loadQuotaData('hosp');
		});

		//MDC点击事件
		$('#'+tabId).off('click','.depGroup');
		$('#'+tabId).on('click','.depGroup',function(){
			
			$('#'+tabId+' #drgList').removeClass('depActive');
			$('#'+tabId+' .depGroup').removeClass('depActive');
			$('#'+tabId+' .hosp').removeClass('depActive');
			$(this).addClass('depActive');
			
			var mdcCode = $(this).attr('id');
			var mdcDesc = $(this).attr('title');
			paramTabPage[tabId]['parmdcCode'] = mdcCode;
			paramTabPage[tabId]['parmdcDesc'] = mdcDesc;
			paramTabPage[tabId]['pardrgCode'] = '';
			$('#'+tabId+' .currDepOrDepgroup').html('<i class="fa fa-stethoscope"></i>'+mdcCode+'-'+mdcDesc);
			
			//DRGs列表
			var param = drgUI.setAjaxData(tabId);
			$.post(contextPath+'/DRGs/getDrgsByParam.dhc',param,
					function(dep){
					$('#'+tabId+' #drgList').html('');
					$('#'+tabId+' #drgList').append('<option value="">全部DRG</option>');
					$.each(dep.data,function(i,n){
						$('#'+tabId+' #drgList').append('<option value="'+n.DRGCODE+'">'+n.DRGCODE+'-'+n.DRGDESC+'</option>');
					});
			});
			
			$('#'+tabId+' #singleDrgs').hide();
			$('#'+tabId+' #multilDrgs').show();
			
			//加载表格
			loadQuotaData('drgs',mdcDesc);
		});

		//drgs选择事件
		$('#'+tabId).off('change','#drgList');//移除之前绑定的事件
		$('#'+tabId).on('change','#drgList',function(){
			$(this).addClass('depActive');
			var drgCode=$('#'+tabId+' #drgList').val();
			var drgDesc=$('#'+tabId+' #drgList').find('option:selected').text();
			paramTabPage[tabId]['pardrgCode'] = drgCode;
			$('#'+tabId+' .currDepOrDepgroup').html('<i class="fa fa-stethoscope"></i>'+drgDesc);

			//加载表格
			if(drgCode=="" || drgCode==null){
				if($('#'+tabId+' .hosp').hasClass('depActive')){
					$('#'+tabId+' #singleDrgs').hide();
					$('#'+tabId+' #multilDrgs').show();
					loadQuotaData('hosp');
				}else if($('#'+tabId+' .depGroup').hasClass('depActive')){
					$('#'+tabId+' #singleDrgs').hide();
					$('#'+tabId+' #multilDrgs').show();
					loadQuotaData('drgs',paramTabPage[tabId].parmdcCode);
				}
			}else{
				$('#'+tabId+' #multilDrgs').hide();
				$('#'+tabId+' #singleDrgs').show();
				loadQuotaData2(drgCode,drgCode);
			}
		});
	}
	
	function loadQuotaData(monitorType,name){
		
		if(paramTabPage[tabId].compareType=="year"){
			compareName = "同期";
		}else if(paramTabPage[tabId].compareType=="month"){
			compareName = "上期";
		}
		var ccode='';
		var ddesc='';
		 if(monitorType=="drgs"){//多个DRG的指标，查询MDC下多个DRG
			 ccode=paramTabPage[tabId].parmdcCode;
			ddesc=name;
		 }
		 if(monitorType=="hosp"){
			 ccode='全院'
			 ddesc='全院';
		 }
		 var drgParamMulti=drgUI.setAjaxData(tabId);
		 drgParamMulti.monitorType='drgs';
		//DRGs病组
		multiDrgQuotaTableData=[];//表格数据
		multiDrgQuotaColumns = [ {
			"data" : null,
			"className" : "details-control",
			"width" : 25
		}, {
			"data" : "ccode1",
			"title" : "DRG病组",
			"render":function(obj,type,full){
				return "<span title=\""+full.ddesc+"\">"+full.ccode+"</span><span>-"+full.ddesc+"<span>";
			}
		} ];//表格列
		deleteInd=-1;		
		var quotas = totalQuota[0].data;
		for(var o in quotas){
			(function(o){//解决for循环闭包问题
				ajaxCntDrgFeeStage.multiple = ajaxCntDrgFeeStage.multiple +1;
				var quotaCode = quotas[o].quotaCode;
				var quotaName = quotas[o].quotaName;
				drgParamMulti["quotaCode"] = quotaCode;
				
				if(quotaName.indexOf("%")>-1){//如果是比率类指标
					var column = { "data": quotaCode,"type":"number-beforeHtml","title":quotaName,
							"render":function(obj, type, full){
								return formatNumber(full[quotaCode])+gridcompareValuePercent(full[quotaCode],full[quotaCode+"cc"]);
							}};
					multiDrgQuotaColumns.push(column);
				}else{
					var column = { "data": quotaCode,"type":"number-beforeHtml","title":quotaName,
							"render":function(obj, type, full){
								return formatNumber(full[quotaCode])+gridcompareValue(full[quotaCode],full[quotaCode+"cc"]);
							}};
					multiDrgQuotaColumns.push(column);
				}
				buildMultiDrgTable(drgParamMulti,quotaCode,quotaName,multiDrgCallBack);
			})(o);
		}
		
		function buildMultiDrgTable(drgParamMulti,quotaCode,quotaName,multiDrgCallBack){
			$.ajax({
				url : contextPath + "/DrgsIndexCal/indexCal.dhc",
				"data" : drgParamMulti,
				type : "post",
				success : function(data) {
					var multiDrgQuotaData = data.data;
					ajaxCntDrgFeeStage.multiple = ajaxCntDrgFeeStage.multiple-1;
					multiDrgCallBack(quotaCode,quotaName,multiDrgQuotaData);
				}
			});
		}
		function multiDrgCallBack(quotaCode,quotaName,multiDrgQuotaData){
			if(multiDrgQuotaData!=null&&multiDrgQuotaData.length>0){
				if(multiDrgQuotaTableData.length==0){
					for ( var cd in multiDrgQuotaData){
						var tmpCode = multiDrgQuotaData[cd]["ccode"];
						var tmpdesc = multiDrgQuotaData[cd]["ddesc"];
						var tmpQV = multiDrgQuotaData[cd]["QuotaValue"];
						var tmpQVCC = multiDrgQuotaData[cd]["QuotaValuecc"];
						
						var tmpStr = "{'ccode':'"+tmpCode+"','ddesc':'"+tmpdesc+"','"+quotaCode+"':'"+tmpQV+"','"+quotaCode+"cc':'"+tmpQVCC+"'}";
						var jsonobj=eval('('+tmpStr+')');
						multiDrgQuotaTableData[cd]=jsonobj;
					}
				}else{
					for ( var cd in multiDrgQuotaData){
						var tmpclinicdata = [];
						if(multiDrgQuotaTableData[cd]){
							tmpclinicdata = multiDrgQuotaTableData[cd];
						}else{
							tmpclinicdata = [];
							tmpclinicdata["ccode"]=multiDrgQuotaData[cd]["ccode"];
							tmpclinicdata["ddesc"]=multiDrgQuotaData[cd]["ddesc"];
						}
						tmpclinicdata[quotaCode]=multiDrgQuotaData[cd]["QuotaValue"];
						tmpclinicdata[quotaCode+"cc"]=multiDrgQuotaData[cd]["QuotaValuecc"];
						multiDrgQuotaTableData[cd]=tmpclinicdata;
					}
				}
			}
		}
		var timerMultiDrg = setInterval(function(){
			if(ajaxCntDrgFeeStage.multiple==0){
				clearInterval(timerMultiDrg);
				//DRGs病组
				multiDrgQuotaColumns.push({ "data": "OPERATION","title":"操作","render": function(obj, type, full) {return "<a class='feeStageOper'>医嘱</a>";}})
				var paramsDatatables={scrollX:true,tableTitle:ccode+'指标情况表',order:[1,'asc'],columnDefs:[{orderable:false,targets:[0,10]}]};
				
				var oTable =$('#'+tabId+' #drgsTable').dataTableBasic(multiDrgQuotaColumns,multiDrgQuotaTableData,paramsDatatables);
				$('#'+tabId+' #drgsTable').off('click','.feeStageOper');
				$('#'+tabId+' #drgsTable').on('click','.feeStageOper',function(){
					var nTr = $(this).closest('tr');
					var row = oTable.row( nTr );
					var rowData=row.data();
					orderDetail(rowData.ccode,rowData.ddesc,'','','drg');
				});
				function format ( d ) {
					return '<div class="col-xs-12" id="'+d.ccode+'">'
			           +'	<div class="row">'
			           +'		<div class="col-xs-6"><div class="stagePie" style="height:260px;"></div></div>'
			           +'		<div class="col-xs-6"><div class="stageLine" style="height:260px;"></div></div>'
			           +'	</div>'
			           +'   <div class="row">'
			           +'		<div class="col-xs-12">'
			           +'			<div class="stageTableDiv paddingd10"></div>'
			           +'     	</div>'
			           +'   </div>'
			           +'</div>';
				}
				$('#'+tabId+' #drgsTable tbody').off("click", "td.details-control"); 
				$('#'+tabId+' #drgsTable tbody').on('click', 'td.details-control', function () {
					var nTr = $(this).closest('tr');
					var row = oTable.row( nTr );
					var aData=row.data();
					if (row.child.isShown()){ //判断是否已打开
						row.child.hide();
						nTr.removeClass("shown");
					} else {
						nTr.addClass("shown");
						row.child(format(aData)).show();
						echartLoadingInit($('#'+tabId+' #'+aData.ccode+' .stageLine'));//loading效果
						echartLoadingInit($('#'+tabId+' #'+aData.ccode+' .stagePie'));//loading效果
			            //分段科室表格
				        var tid='id'+new Date().getTime();
						$('#'+tabId+' #'+aData.ccode+' .stageTableDiv').html('<table id="'+tid+'" class="table"></table>');
						var param=drgUI.setAjaxData(tabId);
						param.monitorType=monitorType;
						param.type1=paramTabPage[tabId].orderSpecialDep;
						param.pardrgCode=aData.ccode;
						$.post(contextPath+"/feeStage/getFeeStageData.dhc", param).done(function(data){
							data = data.data;
							var columns = [
											{ "data": "STAGEDEP","title":"部门"},
						                    { "data": "TOTALCASECNT","type":"number-html","title":"患者数",
						                      "render": function(obj, type, full) {
						                    	  return compareValue(full.TOTALCASECNT, full.TOTALCASECNTcc);
						                      }
						                    },
						                    { "data": "STAGEFEE","type":"number-html","title":"分段费用(万元)",
						                      "render": function(obj, type, full) {
						                    	  return compareValue(full.STAGEFEE, full.STAGEFEEcc);
						                      }
						                    },
						                    { "data": "StageRatio","type":"number-html","title":"分段费用占比(%)",
						                      "render": function(obj, type, full) {
						                    	  return compareValue(full.STAGERATIO, full.STAGERATIOcc);
						                      }
						                    },
						                    { "data": "AvgFee","type":"number-html","title":"次均费用(元)",
						                      "render": function(obj, type, full) {
						                    	  return compareValue(full.AVGFEE, full.AVGFEEcc);
						                      }
						                    },
						                    { "data": "DrugFee","type":"number-html","title":"药品费用(万元)",
						                      "render": function(obj, type, full) {
						                    	  return compareValue(full.DRUGFEE, full.DRUGFEEcc);
						                      }
						                    },
						                    { "data": "DrugRatio","type":"number-html","title":"药占比(%)",
						                      "render": function(obj, type, full) {
						                    	  return comparePercent(full.DRUGRATIO, full.DRUGRATIOcc);
						                      }
						                    },
						                    { "data": "MaterialFee","type":"number-html","title":"耗材费(万元)",
						                      "render": function(obj, type, full) {
						                    	  return compareValue(full.MATERIALFEE, full.MATERIALFEEcc);
						                      }
						                    },
						                    { "data": "MaterialRatio","type":"number-html","title":"耗占比(%)",
						                      "render": function(obj, type, full) {
						                    	  return comparePercent(full.MATERIALRATIO, full.MATERIALRATIOcc);
						                      }
						                    },
						                    { "data": "OrderQuantity","type":"number-html","title":"医嘱项数",
							                      "render": function(obj, type, full) {
							                    	  return compareValue(full.ORDERQUANTITY, full.ORDERQUANTITYcc);
							                      }
						                    },
						                    { "data": "OPERATION","title":"操作","className":"feeStageOperdrg",
						                      "render": function(obj, type, full) {
						                    	  return "<a>医嘱</a>";
						                      }
						                    }
						                 ];
							var paramsDatatable={searching:false,lengthChange:false,info:false,paging:false,tableTitle:aData.ccode+'费用分段指标情况表',order:[2,'desc'],columnsDefs:[{orderabel:false,targets:[0,1,10]}]};
							var drgStageTable=$('#'+tabId+' #'+tid).dataTableBasic(columns,data,paramsDatatable);
							$('#'+tabId+' #'+tid).off('click');
							$('#'+tabId+' #'+tid).on('click','.feeStageOperdrg a',function(){
								var nTr = $(this).closest('tr');
								var row = drgStageTable.row( nTr );
								var rowData=row.data();
								//特殊部门未配置且，当前分段科室为其他时，需特殊处理,拼接现有表格中除其他以外的分段科室
								if(rowData.DEPCATE=='OTHER'&&paramTabPage[tabId].orderSpecialDep==''){
									var noStageDepDescArray=[];
									var tableData=drgStageTable.data().toArray();
									for(var o in tableData){
										if(tableData[o].DEPCATE!='OTHER'){
											noStageDepDescArray.push("'"+tableData[o].STAGEDEP+"'");
										}
									}
									var noStageDepDesc=noStageDepDescArray.join(",");
									orderDetail(aData.ccode,aData.ddesc,rowData.DEPCATE, rowData.STAGEDEP, 'drgStageDep',noStageDepDesc);
								}
								else{
									orderDetail(aData.ccode,aData.ddesc,rowData.DEPCATE, rowData.STAGEDEP, 'drgStageDep');
								}
							});
							
							var stageFeeData = [];
							var avgFeeData = [];
							var drugRatioData = [];
							var avgFeeDatacc = [];
							var drugRatioDatacc = [];
							var stageDepData = [];
							for(var n in data){
								stageFeeData.push({name:data[n].STAGEDEP,value:data[n].STAGEFEE});
								avgFeeData.push(data[n].AVGFEE);
								drugRatioData.push(data[n].DRUGRATIO);
								avgFeeDatacc.push(data[n].AVGFEEcc);
								drugRatioDatacc.push(data[n].DRUGRATIOcc);
								stageDepData.push(data[n].STAGEDEP);
							}
							var charParams={pagemode:true,radius:[0, '50%']};
							pieCharts($('#'+tabId+' #'+aData.ccode+' .stagePie'), stageFeeData, '特殊部门费用分布图', '',charParams);
							var legend=['次均费用(本期)','次均费用('+compareName+')','药占比(本期)','药占比('+compareName+')'];
							var xAxis = [{type : 'category',data : stageDepData}];
							var yAxis = [{type : 'value',name : '次均费用',splitNumber:5,axisLabel : {formatter: '{value} 元'}},
								        {type : 'value',name : '药占比',splitLine:{show:false},axisLabel : {formatter: '{value} %'}}];
							var series = [
									        {name:'次均费用(本期)',type:'bar',data:avgFeeData},
									        {name:'次均费用('+compareName+')',type:'bar',data:avgFeeDatacc},
									        {name:'药占比(本期)',type:'line',yAxisIndex: 1,data:drugRatioData},
									        {name:'药占比('+compareName+')',type:'line',yAxisIndex: 1,data:drugRatioDatacc}
									    ];
							var chartParams={};
							barLineMixChartBasic($('#'+tabId+' #'+aData.ccode+' .stageLine'), legend,series,xAxis,yAxis,'特殊部门次均费用和药占比','',chartParams);
						});
			        }
			    } );
			}
		}, 500);
			
	}
	
	
	
	/**
	 * 加载单个DRG的查询结果，与多个DRG的展示不一样
	 */
	function loadQuotaData2(drgCode,drgDesc){
		
		if(paramTabPage[tabId].compareType=="year"){
			compareName = "同期";
		}else if(paramTabPage[tabId].compareType=="month"){
			compareName = "上期";
		}else if(paramTabPage[tabId].compareType=="manage"){
			compareName = "绩效";
		}else if(paramTabPage[tabId].compareType=="std"){
			compareName = "标杆";
		}
		var ccode='';
		var ddesc='';
		
		//分段科室表格
		$('#'+tabId+' #drgStageTableDiv').html('<table id="drgStageTable" class="table"></table>');
		var param=drgUI.setAjaxData(tabId);
		param.type1=paramTabPage[tabId].orderSpecialDep;
		param.pardrgCode=drgCode;
		$.post(contextPath+"/feeStage/getFeeStageData.dhc", param).done(function(data){
			data = data.data;
			var columns = [
							{ "data": "STAGEDEP","title":"部门"},
		                    { "data": "TOTALCASECNT","type":"number-html","title":"患者数",
		                      "render": function(obj, type, full) {
		                    	  return compareValue(full.TOTALCASECNT, full.TOTALCASECNTcc);
		                      }
		                    },
		                    { "data": "STAGEFEE","type":"number-html","title":"分段费用(万元)",
		                      "render": function(obj, type, full) {
		                    	  return compareValue(full.STAGEFEE, full.STAGEFEEcc);
		                      }
		                    },
		                    { "data": "StageRatio","type":"number-html","title":"分段费用占比(%)",
		                      "render": function(obj, type, full) {
		                    	  return compareValue(full.STAGERATIO, full.STAGERATIOcc);
		                      }
		                    },
		                    { "data": "AvgFee","type":"number-html","title":"次均费用(元)",
		                      "render": function(obj, type, full) {
		                    	  return compareValue(full.AVGFEE, full.AVGFEEcc);
		                      }
		                    },
		                    { "data": "DrugFee","type":"number-html","title":"药品费用(万元)",
		                      "render": function(obj, type, full) {
		                    	  return compareValue(full.DRUGFEE, full.DRUGFEEcc);
		                      }
		                    },
		                    { "data": "DrugRatio","type":"number-html","title":"药占比(%)",
		                      "render": function(obj, type, full) {
		                    	  return comparePercent(full.DRUGRATIO, full.DRUGRATIOcc);
		                      }
		                    },
		                    { "data": "MaterialFee","type":"number-html","title":"耗材费(万元)",
		                      "render": function(obj, type, full) {
		                    	  return compareValue(full.MATERIALFEE, full.MATERIALFEEcc);
		                      }
		                    },
		                    { "data": "MaterialRatio","type":"number-html","title":"耗占比(%)",
		                      "render": function(obj, type, full) {
		                    	  return comparePercent(full.MATERIALRATIO, full.MATERIALRATIOcc);
		                      }
		                    },
		                    { "data": "OrderQuantity","type":"number-html","title":"医嘱项数",
			                      "render": function(obj, type, full) {
			                    	  return compareValue(full.ORDERQUANTITY, full.ORDERQUANTITYcc);
			                      }
		                    },
		                    { "data": "OPERATION","title":"操作","className":"feeStageOperdrg",
		                      "render": function(obj, type, full) {
		                    	  return "<a>医嘱</a>";
		                      }
		                    }
		                 ];
			var paramsDatatable={searching:false,lengthChange:false,info:false,paging:false,tableTitle:'费用分段指标情况表',order:[2,'desc'],columnsDefs:[{orderabel:false,targets:[0,1,10]}]};
			var drgStageTable=$('#'+tabId+' #drgStageTable').dataTableBasic(columns,data,paramsDatatable);
			$('#'+tabId+' #drgStageTable').off('click');
			$('#'+tabId+' #drgStageTable').on('click','.feeStageOperdrg a',function(){
				var nTr = $(this).closest('tr');
				var row = drgStageTable.row( nTr );
				var rowData=row.data();
				
				//特殊部门未配置且，当前分段科室为其他时，需特殊处理,拼接现有表格中除其他以外的分段科室
				if(rowData.DEPCATE=='OTHER'&&paramTabPage[tabId].orderSpecialDep==''){
					var noStageDepDescArray=[];
					var tableData=drgStageTable.data().toArray();
					for(var o in tableData){
						if(tableData[o].DEPCATE!='OTHER'){
							noStageDepDescArray.push("'"+tableData[o].STAGEDEP+"'");
						}
					}
					var noStageDepDesc=noStageDepDescArray.join(",");
					orderDetail(drgCode,drgDesc,rowData.DEPCATE, rowData.STAGEDEP, 'drgStageDep',noStageDepDesc);
				}
				else{
					orderDetail(drgCode,drgDesc,rowData.DEPCATE, rowData.STAGEDEP, 'drgStageDep');
				}
			});
			var stageFeeData = [];
			var avgFeeData = [];
			var drugRatioData = [];
			var avgFeeDatacc = [];
			var drugRatioDatacc = [];
			var stageDepData = [];
			for(var n in data){
				stageFeeData.push({name:data[n].STAGEDEP,value:data[n].STAGEFEE});
				avgFeeData.push(data[n].AVGFEE);
				drugRatioData.push(data[n].DRUGRATIO);
				avgFeeDatacc.push(data[n].AVGFEEcc);
				drugRatioDatacc.push(data[n].DRUGRATIOcc);
				stageDepData.push(data[n].STAGEDEP);
			}
			var charParams={pagemode:true,radius:[0, '50%']};
			pieCharts($('#'+tabId+' #drgStagePie'), stageFeeData, '特殊部门费用分布图', '',charParams);
			var legend=['次均费用(本期)','次均费用('+compareName+')','药占比(本期)','药占比('+compareName+')'];
			var xAxis = [{type : 'category',data : stageDepData}];
			var yAxis = [{type : 'value',name : '次均费用',splitNumber:5,axisLabel : {formatter: '{value} 元'}},
				        {type : 'value',name : '药占比',splitLine:{show:false},axisLabel : {formatter: '{value} %'}}];
			var series = [
					        {name:'次均费用(本期)',type:'bar',data:avgFeeData},
					        {name:'次均费用('+compareName+')',type:'bar',data:avgFeeDatacc},
					        {name:'药占比(本期)',type:'line',yAxisIndex: 1,data:drugRatioData},
					        {name:'药占比('+compareName+')',type:'line',yAxisIndex: 1,data:drugRatioDatacc}
					    ];
			var chartParams={};
			barLineMixChartBasic($('#'+tabId+' #drgStageLine'), legend,series,xAxis,yAxis,'特殊部门次均费用和药占比','',chartParams);
			
		});
	}
	
	$('#'+tabId+' #toDepFeeStage').click(function(){
		openTab('/pages/feeStage/depFeeStage.jsp', '科室费用分段', 'depFeeStage', 'depFeeStage', paramTabPage[tabId]);
	});
	//医嘱弹出框
	function orderDetail(typeCode,typeDesc,stageDepCode, stageDepDesc, type,noStageDepDesc){
		var param=drgUI.setAjaxData(tabId);
		 param.pardrgCode=typeCode;
		 if(type=="drgStageDep"){
			 if(stageDepCode=='OTHER'){//如果是其他，则传入特殊部门
				 if(paramTabPage[tabId].orderSpecialDep==''){//没有配置特殊部门时
					 param.type1=noStageDepDesc;
				 }
				 else{
					 param.type1=paramTabPage[tabId].orderSpecialDep;
				 }
				
			 }
			 else{
				 param.type1=stageDepDesc;
			 }
		 }
		 $.post(contextPath + '/pages/common/top-dialog.jsp').done(function(data){
				var dialog  = $(data);
				dialog.find(".modal-title").html(typeCode+"-"+"医嘱项明细");
				dialog.find(".echartscq").css("height", "420px");
				dialog.modal({
					keyboard: false
				}).on({
					'hidden.bs.modal' : function(){
						$(this).remove();
					},
					'shown.bs.modal' : function(){
						$.post(contextPath + "/feeStage/getOrderData.dhc",param).done(function(data){
							var data = data.data;
							//分段科室表格
							dialog.find(".echartscq").html('<table class="table"></table>');
							var columns = [
											{ "data": "ORDERID","title":"医嘱序号"},
						                    { "data": "ORDERDESC","title":"医嘱项名称","render": function(obj, type, full) {
							   	            	 return linefeedText(obj);
							   	            }
											},
						                    { "data": "ORDERTOTALFEE","title":"医嘱总额(元)",
						                    	"render":function(obj, type, full){
						                    		return formatNumber(full.ORDERTOTALFEE);
						                    	}
						                    },
						                    { "data": "ORDERFEERATIO","title":"金额占比(%)"},
						                    { "data": "AvgOrderFee","title":"次均医嘱金额(元)",
						                    	"render":function(obj, type, full){
						                    		return formatNumber(full.AVGORDERFEE);
						                    	}
						                    },
						                    { "data": "OrderUnitPrice","title":"单价",
						                    	"render":function(obj, type, full){
						                    		return formatNumber(full.ORDERUNITPRICE);
						                    	}
						                    },
						                    { "data": "CaseCnt","title":"使用人次",
						                    	"render":function(obj, type, full){
						                    		return formatNumber(full.CASECNT);
						                    	}
						                    },
						                    { "data": "OrderQuantity","title":"医嘱数量",
						                    	"render":function(obj, type, full){
						                    		return formatNumber(full.ORDERQUANTITY);
						                    	}
						                    }
						                 ];
							var paramsDatatable={scrollY:'300px',tableTitle:'医嘱明细表'};
							dialog.find(".echartscq").find('table').dataTableBasic(columns, data,paramsDatatable);
						   });
					}
				});
		 });
	}
});

